@extends('backend::layout')

@section('title', '编辑设备')

@section('content')
    <form method="post">
        {{ csrf_field() }}
        <div class="box box-primary">
            <div class="box-header with-border">
                <div class="col-lg-4">
                    <h3 class="box-title">编辑设备</h3>
                </div>
            </div>
            <!-- /.box-header -->
            <div class="box-body pad-10">
                <div class="col-lg-4">
                    <div class="form-group @if($errors->has('kind_id')) has-error @endif">
                        <label class="control-label">{{ __("Type") }}：</label>
                        <select class="form-control" name="kind_id">
                            <option value="">{{ __('-- Please Selected --') }}</option>
                            @if(!empty($kinds))
                                @foreach($kinds as $item)
                                    <option value="{{ $item->id }}" @if(old('kind_id') == $item->id || (empty(old('kind_id')) && $device->kind_id == $item->id )) selected @endif>{{ $item->name }}</option>
                                @endforeach
                            @endif
                        </select>
                        @if($errors->has('kind_id'))
                            <span class="help-block">{{ $errors->first('kind_id') }}</span>
                        @endif
                    </div>
                </div>
                <div class="col-lg-4">
                    <div class="form-group @if($errors->has('code')) has-error @endif">
                        <label class="control-label">设备编号</label>
                        <input class="form-control " name="code" type="text" placeholder="编号" value="{{ old('code') ?: $device->code }}">
                        @if($errors->has('code'))
                            <span class="help-block">{{ $errors->first('code') }}</span>
                        @endif
                    </div>
                </div>

                <div class="col-lg-4">
                    <div class="form-group @if($errors->has('get_time')) has-error @endif">
                        <label class="control-label">购买时间</label>

                        <div class="input-group date form_date" data-date="" data-date-format="yyyy-mm-dd HH:ii:ss" data-link-field="dtp_input2" data-link-format="yyyy-mm-dd HH:ii:ss">
                            <input class="form-control" size="16" type="text" name="get_time" value="{{ old('get_time') ?: $device->get_time  }}" readonly>
                            <span class="input-group-addon"><span class="fa fa-lg fa-calendar"></span></span>
                        </div>
                        @if($errors->has('get_time'))
                            <span class="help-block">{{ $errors->first('get_time') }}</span>
                        @endif
                    </div>
                </div>

{{--                <div class="col-lg-4">
                    <div class="form-group @if($errors->has('grade_id')) has-error @endif">
                        <label class="control-label">{{ __("grade") }}：</label>
                        <select class="form-control" name="grade_id">
                            <option value="">{{ __('-- Please Selected --') }}</option>
                            @if(!empty($grades))
                                @foreach($grades as $item)
                                    <option value="{{ $item->id }}" @if(old('grade_id') == $item->id || (empty(old('grade_id')) && in_array($item->id, $deviceGrades) )) selected @endif>{{ $item->name }}</option>
                                @endforeach
                            @endif
                        </select>
                        @if($errors->has('grade_id'))
                            <span class="help-block">{{ $errors->first('grade_id') }}</span>
                        @endif
                    </div>
                </div>--}}

                <div class="col-lg-4">
                    <div class="form-group">
                        <label class="control-label">{{ __("grade") }}：</label>
                        @if(!empty($grades))
                            @foreach($grades as $item)

                                <div class="radio">
                                    <label>
                                        <input type="checkbox" value="{{ $item->id }}" @if( (old('grade_id') && in_array($item->id, old('grade_id'))) || (empty(old('grade_id')) && in_array($item->id, $deviceGrades)) ) checked @endif name="grade_id[]">
                                        {{ $item->name }}
                                    </label>
                                </div>
                            @endforeach
                        @endif

                        @if($errors->has('grade_id'))
                            <span class="help-block text-danger">{{ $errors->first('grade_id') }}</span>
                        @endif
                    </div>
                </div>

            </div>
            <!-- /.box-body -->
            <div class="box-footer m-b-2">
                <div class="col-lg-4">
                    <button class="btn btn-primary btn-sm" type="submit">
                        <i class="fa fa-check"></i> {{ __('Save') }}
                    </button>
                    &nbsp;&nbsp;&nbsp;
                    <a class="btn btn-default btn-sm" href="javascript:history.back(-1);">
                        <i class="fa fa-undo"></i> {{ __('Back') }}
                    </a>
                </div>
            </div>
            <!-- /.box-footer -->
        </div>
    </form>
@stop

@section('script')
    <script>
        !function ($) {
            $(function () {
                $('.form_date').datetimepicker({
                    language:  'zh-CN',
                    weekStart: 1,
                    todayBtn:  1,
                    autoclose: 1,
                    todayHighlight: 1,
                    startView: 2,
                    minView: 2,
                    forceParse: 0
                });
            });
        }(jQuery);

    </script>
@stop